// pages/hot/hot.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperphoto: [
      "https://pic.maizuo.com/usr/movie/24c343e5bed9f0e75b4a676e77d591ae.jpg?x-oss-process=image/quality,Q_70",
      "https://pic.maizuo.com/usr/movie/b991c2beb84101ae0585308c7b282217.jpg?x-oss-process=image/quality,Q_70",
      "https://pic.maizuo.com/usr/movie/6c47eb5dc41e76cb7eaa8b48198cb486.jpg?x-oss-process=image/quality,Q_70",
      "https://pic.maizuo.com/usr/movie/9bb7b0f4d4256fd386b90b55d2094199.jpg?x-oss-process=image/quality,Q_70",
      "https://pic.maizuo.com/usr/movie/94d069d3e037bb221d7b4b581ccaff51.jpg?x-oss-process=image/quality,Q_70",
      "https://pic.maizuo.com/usr/movie/37c604f9c5c165b8fd110a926037f8c1.jpg?x-oss-process=image/quality,Q_70",
      "https://pic.maizuo.com/usr/movie/5e82a75851f5aa1d23c7e2cf84ef4f85.jpg?x-oss-process=image/quality,Q_70",
    ],
    hotfilms: [],
    comingfilms: [],
    city: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getHotMovieList()
    this.getComingMovieList()
    this.getCityData()
  },
  //获取热映电影数据
  getHotMovieList: function () {
    if (this.data.city) {
      var id = this.data.city.cityId
    } else {
      var id = "110100"
    }
    wx.request({
      url: 'https://api.iynn.cn/film/api/v1/getNowPlayingFilmList?cityId=' + id,
      success: (result) => {
        this.setData({
          hotfilms: result.data.data.films
        })
      },
    })
  },

  //获取即将上映数据
  getComingMovieList: function () {
    if (this.data.city) {
      var id = this.data.city.cityId
    } else {
      var id = "110100"
    }
    wx.request({
      url: 'https://api.iynn.cn/film/api/v1/getComingSoonFilmList?cityId=' + id,
      success: (result) => {
        //console.log(result.data.data.films)
        this.setData({
          comingfilms: result.data.data.films
        })
      },
    })
  },
  changecity: function () {
    wx.navigateTo({
      url: '/pages/city/city',
    })
  },
  getCityData: function () {
    var city = wx.getStorageSync('city')
    //没拿到就不赋值
    if (!city) {
      return
    }
    this.setData({
      city: city
    })
    this.getHotMovieList()
    this.getComingMovieList()
  },
  gotoDetail: function (e) {
    //console.log(e.currentTarget.dataset.filmid)
    const filmid = e.currentTarget.dataset.filmid
    wx.navigateTo({
      url: '/pages/movieDetail/movieDetail?id='+filmid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getCityData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})